<!--
 * @Author: [yuantongxin]
 * @Date: 2021-09-17 14:07:12
 * @LastEditors: [yuantongxin]
 * @LastEditTime: 2021-09-23 19:39:48
 * @Description: 
-->
<template>
    <div>
        <!-- 头部 -->
        <!-- {{category}} -->
        <div class="header">
        <div class="header_main">
          
             <div class="wrapper">
               <img src="../assets/resoure/img/sx_02.jpg" alt="">
               <div class="right" @click="toHome()">学院主页</div> 
                <div class="search">
                  <input type="text" class="txt">
                  <span  class="iconfont icon-sousuo btn"></span>
                </div>
            </div>
        </div>

          <div class="header_top">
            <!-- 容器居中 -->
            <div class="wrapper">
            
            
             <ul>
                <li :class="$route.query.name===item.name?'current':''"
                v-for="item in category" :key="item.id" @click="toJump(item)">{{item.name}}</li>    
                </ul> 
            </div>
          </div>

        </div>
        <!-- /头部 -->
    </div>
</template>

<script>
import {get} from '../utils/request'
export default {
    data(){
        return {
            category:[]
        }
    },
    created(){
        this.loadCategory()
    },
    methods:{
        toHome(){
          //跳转到主页
          this.$router.push({
            path:'/home',
          })
        },
        //所有路径都要写在方法中
        loadCategory(){
            let url = '/index/category/findAll'
            get(url).then(res=>{
                this.category = res.data
            })

        },
        //加载所有栏目
        toJump(item){
            //跳转到list页面 编程式路由导航
            //alert(JSON.stringify(item))
          
                this.$router.push({
                //跳转的路径和携带的参数
                path:'/list',
                query:item      //query:{id,name,title}
                })
            
            //  if(item.name=='风采'){
            //     this.$router.push({
            //     //跳转的路径和携带的参数
            //     path:'/Article',
            //     query:{item}
            //     })
            // }
        }
    },
}
</script>

<style lang="scss">
.header{

  background-image: url('../assets/resoure/img/bg_01.jpg');
  // background-repeat: no-repeat;

    // 头部开始
.header_top {
  // background-color: #2163c1;
  color: #fff;
  .wrapper{
    //  background-image: url(/resoure/img/sx_02.jpg);
    //  height: 120px;
    background-color: #f5f5f5;
    ul{
      display: flex;
      justify-content: space-evenly;
      li{
          padding: .8em 1em;
          color: #1e58b3;
          font-size: 18px;
          font-weight: bold;
      }
       li:hover {
        // background-color: #028b39;
        color: #71c1ff;
        cursor: pointer;
      }
      li.current{
        // background-color: #028b39;
        color: #061b74;
        cursor: pointer;
      }
    }
 
    
  }
}

.header_main{
  // background-color: #1e5dba;
  .wrapper{
  
     position: relative;
     .search{
        position: absolute;
       bottom: 30px;
       right: 20px;
       width: 160px;
     }
     .search .txt{
        height: 30px;
        padding: 0px 10px;
        background-color: #f9f9f9;
        font-size: 14px;
        color: #666;
        line-height: 30px;
        border-radius: 20px;
        position: relative;
     }
     .search .txt{
       cursor:text;
     }
     .search .btn:hover{
       cursor: pointer;
     }
     .search .btn {
  
      right: 5px;
      position: absolute;
      font-size: 22px;
      color: #666;
      line-height: 30px;
     }
    
    .right {
      position: absolute;
      bottom: 25px;
      right: 250px;
       padding: .8em 1em;
        color: #fff;
        font-size: 16px;
        font-weight: bold;
        
      
    }
    .right:hover{
      cursor: pointer;
    }
  }
 
}
}
//头部结束
</style>
